package utils;
 
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

/**
 *
 * @author senai-sc
 */
public class JpaUtils {

    private static EntityManagerFactory factory = null;
    
    private JpaUtils() {
    }
    
    public static EntityManager getEntityManager() {
        if (factory == null || !factory.isOpen()) {
            factory = Persistence.createEntityManagerFactory("TrabalhoFinal");
        }
        return factory.createEntityManager();
    }
    
    public static void close() {
        if (factory == null || !factory.isOpen()) {
            factory.close();
        }
    }
    
}
